//
//  StatusModel.swift
//  weiboLQ
//
//  Created by 半缘君 on 15/12/11.
//  Copyright © 2015年 banyuanjun.cn. All rights reserved.
//

import UIKit

class StatusViewModel {
//    static let shareStatusModel = StatusViewModel(status: <#T##StatusModel#>))
    
    var status:StatusModel
    
    ///头像地址URL
    var URLForIconImge:NSURL? {
        let urlString = status.user?.profile_image_url ?? ""
        return NSURL(string: urlString)
    }
    /// 用户默认头像
    var defaultIconImage:UIImage {
         return UIImage(named: "avatar_default_big")!
    }
    /// 昵称
    var textForNameLable:String {
        return status.user?.screen_name ?? ""
    }
    ///等级图标
    var imageForLevel: UIImage? {
        let level = status.user?.mbrank
        if level! > 0 && level! < 7{
        return UIImage(named:"common_icon_membership_level\((status.user?.mbrank)!)")
        }
        return nil
    }
    /// vip图像
    var imageForVip: UIImage? {
//        认证类型，-1：没有认证，0，认证用户，2,3,5: 企业认证，220: 
        switch (status.user?.verified_type ?? -1) {
        case 0: return UIImage(named: "avatar_vip")!
        case 2,3,5:return UIImage(named: "avatar_enterprise_vip")!
        case 220:return UIImage(named: "avatar_grassroot")!
        default:return nil
        }
    }
    /// 时间
    var textForTimeLabel:String {
        return status.created_at ?? ""
    }
    /// 来源
    var textForSourceLabel:String {
        return status.source ?? ""
    }
    
    /// 缩略图的地址数组
    var thumbnail_pics:[NSURL]?

    ///行高属性
    lazy var rowHeight:CGFloat = {
        
        
//        let v = (self.status.retweeted_status != nil) ? HomeRetweetedCell() : HomeNormalViewCell()
//        HomeRetweetedCell(style: .Default, reuseIdentifier: HomeRetweetedCell)
         let v = (self.status.retweeted_status != nil) ? HomeRetweetedCell(style: .Default, reuseIdentifier: HomeRetweetedCellID) : HomeNormalViewCell(style: .Default, reuseIdentifier: HomeNormalViewCellID)
//        print(self.status.retweeted_status)
        
//        print(v.self)
        return v.getRowHeightWithStatue(self)
    }()
    
    ///转发微薄的正文
    var textForRetweetedLable :String? {
        //判断是不是转发微博
        guard let s = status.retweeted_status else {
            return nil
        }
        return "@" + (s.user?.screen_name ?? "") + ":" + (s.text ?? "")
    }
    ///重用标示符
    var reuseID :String {
        return (status.retweeted_status != nil) ? HomeRetweetedCellID : HomeNormalViewCellID
    }
    
    
    ///构造方法
    init(status:StatusModel){
        self.status = status
        
        if let urlS = status.retweeted_status?.pic_urls ??
            status.pic_urls{
                
                thumbnail_pics = [NSURL]()
                
                for dic in urlS{
                    let url = NSURL(string: dic["thumbnail_pic"]!)
                    thumbnail_pics?.append(url!)
                }
                
        }
        
    }
}

